package edu.hebeu.evil.freshmenguide.Activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import edu.hebeu.evil.freshmenguide.R;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.Activity
 * 时间：16-7-7 下午1:57
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
public class WebViewActivity extends BaseActivity
{
    private WebView webView;

    @Override
    public int setContentView()
    {
        return R.layout.webview;
    }

    @Override
    public String setToolbarTitle()
    {
        return getIntent().getStringExtra("title");
    }

    @Override
    public void onCreate()
    {
        initView();
        webView.loadUrl(getIntent().getStringExtra("url"));
    }

    private void initView()
    {
        webView = (WebView) findViewById(R.id.webView);
    }


    private void setWebView()
    {
        WebSettings webSettings = webView.getSettings();

        /*设置适应屏幕*/
        {
            webSettings.setUseWideViewPort(true);//设置此属性，可任意比例缩放
            webSettings.setLoadWithOverviewMode(true);
        }
        /*支持缩放*/
        {
            webSettings.setJavaScriptEnabled(true);
            webSettings.setBuiltInZoomControls(true);
            webSettings.setSupportZoom(true);
        }
        /*支持手动输入*/
        {
            //webView.requestFocusFromTouch();
        }

        /*优先使用缓存*/
        {
            webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
            // 开启 DOM storage API 功能
            webSettings.setDomStorageEnabled(true);
        }

        /*在当前页面打开新的链接*/
        webView.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });
    }
}
